import { commonApi } from '/api/common'

Page({
  submitLock: false,
  data: {
    content: '',
    url: 'https://houdong.ecoac.cn/map.html',
    type: '' as ReportType,
    id: 0,
  },
  onLoad(query: PageQuery) {
    this.setData({
      type: query.type,
      id: +query.id,
    })
  },
  onInput({ detail }: any) {
    this.setData!({ content: detail.value })
  },
  message: function (e: any) {
    console.log('收到来自页面的信息：', e.detail.data)
  },
  onShareAppMessage: function () {},
  async onSubmit() {
    if (this.submitLock || !this.data.content) return
    this.submitLock = true
    wx.showNavigationBarLoading()
    const { type, id, content } = this.data
    await commonApi.reportContent(type, id, content)
    wx.hideNavigationBarLoading()
    wx.showToast({
      title: '举报成功',
      icon: 'success',
    })
    setTimeout(() => {
      wx.navigateBack({ delta: 1 })
    }, 1000)
  },
})

interface PageQuery extends WechatMiniprogram.IAnyObject {
  type: ReportType
  id: string
}
